package com.erpanderp.wam.ac.view.project;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.AjaxBehaviorEvent;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.swing.SwingWorker;

import org.primefaces.component.menuitem.MenuItem;
import org.primefaces.component.selectonemenu.SelectOneMenu;
import org.primefaces.context.RequestContext;
import org.primefaces.event.RowEditEvent;
import org.primefaces.event.UnselectEvent;

import com.erpanderp.wam.ac.model.entity.project.Journey;
import com.erpanderp.wam.ac.model.entity.project.ProjectAssignment;
import com.erpanderp.wam.ac.model.entity.project.ProjectAssignmentDetail;
import com.erpanderp.wam.ac.model.entity.project.VISA;
import com.erpanderp.wam.ac.model.service.project.JourneyDAO;
import com.erpanderp.wam.ac.model.service.project.ProjectAssignmentDAO;
import com.erpanderp.wam.ac.model.service.project.ProjectAssignmentDetailDAO;
import com.erpanderp.wam.tm.model.service.RRFDAO;
import com.erpanderp.wam.usm.model.entity.projectandassignment.EmployeeProject;
import com.erpanderp.wam.usm.model.entity.projectandassignment.Project;
import com.erpanderp.wam.usm.model.entity.timesheet.TimesheetDetail;
import com.erpanderp.wam.usm.model.entity.user.Employee;
import com.erpanderp.wam.usm.model.entity.user.EmployeeAndReporting;
import com.erpanderp.wam.usm.model.entity.user.NewJoinee;
import com.erpanderp.wam.usm.model.entity.user.PassportAndPANDetails;
import com.erpanderp.wam.usm.model.entity.user.WAMUser;
import com.erpanderp.wam.usm.model.service.projectandassignment.EmployeeProjectDAO;
import com.erpanderp.wam.usm.model.service.projectandassignment.ProjectDAO;
import com.erpanderp.wam.usm.model.service.timesheet.TimesheetDetailDAO;
import com.erpanderp.wam.usm.model.service.user.EmployeeAndReportingDAO;
import com.erpanderp.wam.util.CommonLookup;
import com.erpanderp.wam.util.EmailUtil;
import com.erpanderp.wam.util.ValidationUtil;
import com.erpanderp.wam.util.WAMHostManager;
import com.sun.corba.se.impl.protocol.giopmsgheaders.Message;
@ManagedBean
@ViewScoped
public class InternationalProjectAssignmentFormBean implements Serializable {


	private static final long serialVersionUID = 1L;
	HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
	HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
	ServletContext context = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();

	private String selectedButton = CommonLookup.CREATE_PA_BUTTON;
	private boolean createInternationalProjectAssignmentForm;
	private boolean InternationalProjectAssignmentsList;
	
	///CREATE INTERNATIONAL PROJECT
	ProjectDAO projectDAO = new ProjectDAO();
	ProjectAssignmentDAO projectAssignmentDAO = new ProjectAssignmentDAO();
	RRFDAO rrfDAO = new RRFDAO();
	EmployeeAndReportingDAO employeeAndReportingDAO = new EmployeeAndReportingDAO();
	JourneyDAO onwardJourneyDAO = new JourneyDAO();
	JourneyDAO returnJourneyDAO = new JourneyDAO();
	
	
	private boolean FORM_VALID;
	
	private ProjectAssignment projectAssignment = new ProjectAssignment();
	private ProjectAssignmentDetail projectAssignmentDetail = new ProjectAssignmentDetail();
	private Journey onwardJourney = new Journey();
	private Journey returnJourney = new Journey();
	private VISA visa = new VISA();
	private Employee employee = new Employee();
	private NewJoinee newJoinee = new NewJoinee();
	private PassportAndPANDetails passportAndPANDetails = new PassportAndPANDetails();
	private EmployeeAndReporting employeeAndReporting = new EmployeeAndReporting();
	
	private EmployeeProject  employeeProject = new EmployeeProject();
	
	EmployeeProjectDAO employeeProjectDAO = new EmployeeProjectDAO();
	private List<EmployeeProject> employeeProjects = new ArrayList<EmployeeProject>();
	
	private List<Project> projects = new ArrayList<Project>();
	private List<PassportAndPANDetails> passportAndPANDetailsList = new ArrayList<PassportAndPANDetails>();
	private Map<String, Long> projectsMap = new HashMap<String, Long>();
	private List<Journey> onwardJourneyDetails = new ArrayList<Journey>();
	private List<Journey> returnJourneyDetails = new ArrayList<Journey>();
	private List<Journey> onwardJournies = new ArrayList<Journey>();
	private List<Journey> returnJournies = new ArrayList<Journey>();
	
	
	private Long selectedProjectId;
	private Project selectedProject= new Project();
	
	private WAMUser wamUser = new WAMUser();
	private String InternationalProjectAssignmentCode;
	private String employeeId;
	private String passportNumber;
	private String contactNumber="";
	private String approvedBy="";
	private Float advanceAmount;
	private Float roomRentAdvance;
	private Date createDate;
	private String additionals;
	String EMAIL_MESSAGE;
	
	private Employee reportingManager = new Employee();
	private Long reportingManagerId;
	private EmailUtil emailUtil = new EmailUtil();
	private TimeZone defaultTimeZone = TimeZone.getDefault();

	///INTERNATIONAL PROJECT ASSIGNMENT LIST
	//ProjectDAO projectDAO = new ProjectDAO();
	//ProjectAssignmentDAO projectAssignmentDAO = new ProjectAssignmentDAO();
	ProjectAssignmentDetailDAO projectAssignmentDetailDAO = new ProjectAssignmentDetailDAO();
	
	//private ProjectAssignment projectAssignment = new ProjectAssignment();
	//private ProjectAssignmentDetail projectAssignmentDetail = new ProjectAssignmentDetail();
	//private Employee employee = new Employee();
	//private Project selectedProject= new Project();
	//private WAMUser wamUser = (WAMUser) session.getAttribute(CommonLookup.SESSION_ATTRIBUTE_WAMUSER);
    //private Employee reportingManager;
	
	private boolean SHOW_EDIT_DIALOG=false;
	//private boolean FORM_VALID;
	private boolean renderApproveReject;
	private boolean renderUpdate;
	private boolean renderClose;
	private boolean renderProjectsAssignmentsList;
	private boolean renderProjectsAssignments;
	
	private List<ProjectAssignment> projectAssignmentsList = new ArrayList<ProjectAssignment>();
	private List<ProjectAssignmentDetail> projectAssignmentDetailList = new ArrayList<ProjectAssignmentDetail>();
	//private List<PassportAndPANDetails> passportAndPANDetailsList = new ArrayList<PassportAndPANDetails>();
	
	//private List<Project> projects = new ArrayList<Project>();

   // Map<String, Long> projectsMap = new HashMap<String, Long>();
	
	private Long projectAssignmentId;
	//private Long selectedProjectId;
	
	private String projectAssignmentCode;
	//private String employeeId;
	//private String contactNumber="";
	//private String passportNumber;
	//private String approvedBy="";
	//private Float advanceAmount;
	//private Float roomRentAdvance;
	//private Date createDate;
	//private String additionals;

	public InternationalProjectAssignmentFormBean(){
		System.out.println("constructor start.................");
		System.out.println("projectAssignment.getEmergencycontactNumber()....................."+projectAssignment.getEmergencycontactNumber());
		
		///CREATE INTERNATIONAL PROJECT
		setWamUser((WAMUser) session.getAttribute(CommonLookup.SESSION_ATTRIBUTE_WAMUSER));
		InternationalProjectAssignmentCode=CommonLookup.getAutoGeneratedInternationalProjectAssignmentCode(wamUser.getEmployee().getEmployeeCode());
		System.out.println("InternationalProjectAssignmentId.........."+InternationalProjectAssignmentCode);
		setCreateDate(new Date());
		employee.setFirstName(wamUser.getEmployee().getFirstName());
		employee.setLastName(wamUser.getEmployee().getLastName());
		setEmployeeId(wamUser.getEmployee().getEmployeeCode());
		//wamUser.getEmployee().getNewJoinee().getPassportAndPANDetails();
		setPassportNumber("AD45567H890");
//		passportAndPANDetailsList.addAll(wamUser.getEmployee().getNewJoinee().getPassportAndPANDetails());
//		for(PassportAndPANDetails passportAndPANDetails : passportAndPANDetailsList){
//		setPassportNumber(passportAndPANDetails.getPassportNumber());
//			
//		}
		setContactNumber(wamUser.getEmployee().getTelephone());
		setApprovedBy(CommonLookup.PROJECTASSIGNMENT_DOMESTIC_INTERNATIONAL_APPROVER);
		
		//reportingManager = rrfDAO.getReportingManager(wamUser.getEmployee().getEmployeeId());
		employeeAndReporting = employeeAndReportingDAO.getEmployeeReportingDetail(wamUser.getEmployee().getEmployeeId());
		  
		System.out.println("reportingManager.........."+employeeAndReporting);
		 
		//Getting list of projects
		 employeeProjects = employeeProjectDAO.getAllEmployeeProjects(wamUser.getEmployee().getEmployeeId());
		  for(EmployeeProject employeeProject :employeeProjects)
		  {
			  projectsMap.put(employeeProject.getProject().getProjectName(), employeeProject.getProject().getProjectId());
		  }
		  
		  ///INTERNATIONAL PROJECT ASSIGNMENT
			setRenderProjectsAssignments(false);
			//HR and VP can view all
			//PM can view only those he can approve
			//EMP can view only his request.
			projectAssignment.setProject(new Project());
			projectAssignmentsList = projectAssignmentDAO.getProjectAssignmentsByEmployeeIdProjectType(wamUser.getEmployee().getEmployeeId(),CommonLookup.PROJECT_ASSIGNMENT_TYPE_INTERNATIONAL);
			System.out.println("constructor end...................");
			createInternationalProjectAssignmentForm = true;
	    	InternationalProjectAssignmentsList = false;
			
	}	

	public void buttonChangeListner(ActionEvent e){
		selectedButton = (((MenuItem)e.getComponent()).getValue().toString());
    if(selectedButton.equals(CommonLookup.CREATE_PA_BUTTON))
    {
    	createInternationalProjectAssignmentForm = true;
    	InternationalProjectAssignmentsList = false;
		
	 }
    else if(selectedButton.equals(CommonLookup.VIEWUPDATE_PA_BUTTON))
    {
    	InternationalProjectAssignmentsList = true;
		  createInternationalProjectAssignmentForm = false;
		 
	 }
	 }
	
	///CRETAE INTERNATIONAL PROJECT
	public void projectChangeListener(AjaxBehaviorEvent e) {
		
		if(selectedProjectId == null || selectedProjectId == 0)
		{
		
		}
		else
		{
			selectedProject = projectDAO.getProjectByProjectID(selectedProjectId);
		}
		 }
		
		public String reinitOnward() {  
		    
		 System.out.println("In reinitOnward.....");
		 
		 //projectAssignment = new ProjectAssignment();
		 validateFormOnward();
			if(FORM_VALID){
		 onwardJourney.setCreateDate(new Date());
		 onwardJourney.setCreatedBy(wamUser.getEmployee().getFirstName() +" "+ wamUser.getEmployee().getLastName());
		 onwardJourney.setJourneyType(CommonLookup.JOURNEY_TYPE_ONWARD);
		 onwardJourney.setStatus(CommonLookup.STATUS_ACTIVE);
		 onwardJourney.setProjectAssignment(projectAssignment);
		 projectAssignment.getOnwardJourneyDetails().add(onwardJourney);
		 System.out.println("projectAssignment........"+projectAssignment.getOnwardJourneyDetails().add(onwardJourney));
		 onwardJourney = new Journey();
		
			}
			 return null;  
			 } 
		//VALIDATION FOR ONWARD JOURNEY
		private void validateFormOnward()
		{
			System.out.println("validateForm.....................");
			FORM_VALID = true;

			System.out.println("onwardJourney.getModeOfTravel()....................."+onwardJourney.getModeOfTravel());

			if(onwardJourney.getModeOfTravel().equals("Choose One"))
		{
				FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Choose Mode of travel for onward journey ", ""));
			FORM_VALID = false;
		}
		if(ValidationUtil.isEmpty(String.valueOf(onwardJourney.getNameOfCarrier()), "Name of carrier for onward journey ", null, FacesContext.getCurrentInstance()) != null){
			FORM_VALID = false;
		}

		if(ValidationUtil.isEmpty(String.valueOf(onwardJourney.getCarrierId()), "CarrierId for onward journey ", null, FacesContext.getCurrentInstance()) != null){
			FORM_VALID = false;
		}

		if(ValidationUtil.isEmpty(String.valueOf(onwardJourney.getSource()), "From for onward journey ", null, FacesContext.getCurrentInstance()) != null){
			FORM_VALID = false;
		}

		if(ValidationUtil.isEmpty(String.valueOf(onwardJourney.getDestination()), "To for onward journey ", null, FacesContext.getCurrentInstance()) != null){
			FORM_VALID = false;
		}

		if(ValidationUtil.isEmpty(onwardJourney.getDepartureDate() != null ? onwardJourney.getDepartureDate().toString() :null , "Departure date for onward journey ", null, FacesContext.getCurrentInstance()) != null){
			FORM_VALID = false;
		}

		if(ValidationUtil.isEmpty(onwardJourney.getArrivalDate() != null ? onwardJourney.getArrivalDate().toString() :null , "Arrival date for onward journey ", null, FacesContext.getCurrentInstance()) != null){
			FORM_VALID = false;
		}

		if(ValidationUtil.isEmpty(onwardJourney.getDepartureTime() != null ? onwardJourney.getDepartureTime().toString() :null , "Departure time for onward journey ", null, FacesContext.getCurrentInstance()) != null){
			FORM_VALID = false;
		}

		if(ValidationUtil.isEmpty(onwardJourney.getArrivalTime() != null ? onwardJourney.getArrivalTime().toString() :null , "Arrival time for onward journey ", null, FacesContext.getCurrentInstance()) != null){
			FORM_VALID = false;
		}
		if(onwardJourney.getDepartureDate() != null && onwardJourney.getArrivalDate() != null )
		{
			if(onwardJourney.getDepartureDate().compareTo(onwardJourney.getArrivalDate())>0){	
				System.out.println("FROMDATE is after TODATE");
				FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_WARN," Departure Date should not be more than Arrival Date in onward journey", ""));
				FORM_VALID = false;
			}
		}
				

		}
		

		public void removeFromOnwardJourneyList()
		{
			System.out.println("IN REMOVE METHOD");
		}
		
		public String reinitReturn() {  
		   
		    
		System.out.println("In reinitReturn.....");
		//projectAssignment = new ProjectAssignment();
		validateFormReturn();
		if(FORM_VALID){
		returnJourney.setCreateDate(new Date());
		returnJourney.setCreatedBy(wamUser.getEmployee().getFirstName() +" "+ wamUser.getEmployee().getLastName());
		returnJourney.setJourneyType(CommonLookup.JOURNEY_TYPE_RETURN);
		returnJourney.setStatus(CommonLookup.STATUS_ACTIVE);
		returnJourney.setProjectAssignment(projectAssignment);
		projectAssignment.getReturnJourneyDetails().add(returnJourney);
		System.out.println("projectAssignment........"+projectAssignment.getReturnJourneyDetails().add(returnJourney));
		returnJourney = new Journey();
		//
		}
		return null;  
		} 
		
		private void validateFormReturn()
		{
			System.out.println("validateForm.....................");
			FORM_VALID = true;
			if(returnJourney.getModeOfTravel().equals("Choose One"))
			{
					FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Choose Mode of travel for return journey ", ""));
				FORM_VALID = false;
			}
			
			if(ValidationUtil.isEmpty(String.valueOf(returnJourney.getNameOfCarrier()), "Name of carrier for return journey ", null, FacesContext.getCurrentInstance()) != null){
				FORM_VALID = false;
			}
			
			if(ValidationUtil.isEmpty(String.valueOf(returnJourney.getCarrierId()), "CarrierId for return journey ", null, FacesContext.getCurrentInstance()) != null){
				FORM_VALID = false;
			}
			
			if(ValidationUtil.isEmpty(String.valueOf(returnJourney.getSource()), "From for return journey ", null, FacesContext.getCurrentInstance()) != null){
				FORM_VALID = false;
			}
			
			if(ValidationUtil.isEmpty(String.valueOf(returnJourney.getDestination()), "To for return journey ", null, FacesContext.getCurrentInstance()) != null){
				FORM_VALID = false;
			}
			
			if(ValidationUtil.isEmpty(returnJourney.getDepartureDate() != null ? returnJourney.getDepartureDate().toString() :null , "Departure date for return journey ", null, FacesContext.getCurrentInstance()) != null){
				FORM_VALID = false;
			}
			
			if(ValidationUtil.isEmpty(returnJourney.getArrivalDate() != null ? returnJourney.getArrivalDate().toString() :null , "Arrival date for return journey ", null, FacesContext.getCurrentInstance()) != null){
				FORM_VALID = false;
			}
			
			if(ValidationUtil.isEmpty(returnJourney.getDepartureTime() != null ? returnJourney.getDepartureTime().toString() :null , "Departure time for return journey ", null, FacesContext.getCurrentInstance()) != null){
				FORM_VALID = false;
			}
			
			if(ValidationUtil.isEmpty(returnJourney.getArrivalTime() != null ? returnJourney.getArrivalTime().toString() :null , "Arrival time for return journey ", null, FacesContext.getCurrentInstance()) != null){
				FORM_VALID = false;
			}
			if(returnJourney.getDepartureDate() != null && returnJourney.getArrivalDate() != null )
			{
			if(returnJourney.getDepartureDate().compareTo(returnJourney.getArrivalDate())>0){
				
	    		System.out.println("FROMDATE is after TODATE");
	    		FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_WARN," Departure Date should not be more than Arrival Date in return journey", ""));
	    		FORM_VALID = false;
	    	}
			}
			
			
		}
		public void removeFromReturnJourneyList()
		{
			System.out.println("IN REMOVE METHOD");
		}
		
	
			
			
		//SAVE METHOD
		
		public String saveInternationalProjectAssignmentAction() 
		{
			validateForm();
			if(FORM_VALID){
				System.out.println("saveInternationalProjectAssignmentAction............");
			emailUtil = new EmailUtil();
			projectAssignment.setProjectAssignmentCode(InternationalProjectAssignmentCode);
			projectAssignment.setEmployee(wamUser.getEmployee());
			visa.setEmployee(wamUser.getEmployee());
			projectAssignment.setContactNumber(wamUser.getEmployee().getTelephone());
			//projectAssignment.setRecommendedBy(selectedProject.getOwner().getFirstName() +" "+ selectedProject.getOwner().getLastName());
			projectAssignment.setApprovedBy(CommonLookup.PROJECTASSIGNMENT_DOMESTIC_INTERNATIONAL_APPROVER);
			projectAssignment.setProjectManager(employeeAndReporting.getProjectManager());
			projectAssignment.setRecommendationStatus(CommonLookup.PROJECT_ASSIGNMENT_INPROCESS_STATUS);
 			projectAssignment.setApprovalStatus(CommonLookup.PROJECT_ASSIGNMENT_INPROCESS_STATUS);
 			projectAssignment.setProject(selectedProject);
 			projectAssignment.setProjectType(CommonLookup.PROJECT_ASSIGNMENT_TYPE_INTERNATIONAL);
 			projectAssignment.setCreateDate(new Date());
 			onwardJourney.setCreateDate(new Date());
 			returnJourney.setCreateDate(new Date());
 			visa.setCreateDate(new Date());
 			projectAssignment.setCreatedBy(wamUser.getEmployee().getFirstName() +" "+ wamUser.getEmployee().getLastName());
 			onwardJourney.setCreatedBy(wamUser.getEmployee().getFirstName() +" "+ wamUser.getEmployee().getLastName());
 			returnJourney.setCreatedBy(wamUser.getEmployee().getFirstName() +" "+ wamUser.getEmployee().getLastName());
 			onwardJourney.setJourneyType(CommonLookup.JOURNEY_TYPE_ONWARD);
 			returnJourney.setJourneyType(CommonLookup.JOURNEY_TYPE_RETURN);
 			visa.setCreatedBy(wamUser.getEmployee().getFirstName() +" "+ wamUser.getEmployee().getLastName());
 			projectAssignment.setStatus(CommonLookup.STATUS_ACTIVE);
 			visa.setStatus(CommonLookup.STATUS_ACTIVE);
 			projectAssignment.getVisaDetails().add(visa);
 			
 			if(projectAssignmentDAO.createInternationalProjectAssignment(projectAssignment) != null){
 				System.out.println("AT CALLER METHOD: " + sendMessage());
 				FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, projectAssignment.getProjectAssignmentId() + " ProjectAssignment created successfully.", ""));
 				projectAssignment = new ProjectAssignment();
 			}else{
 				FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "Failed to create ProjectAssignment.", ""));
 			}
 		
			}
		else
		{
			
		}
		System.out.println("In save ProjectAssignment");
		return null;
		}
		
		//Email Functionality
				public String sendMessage(){
					Map<String, String> hostsMap = WAMHostManager.getWAMHosts(context);
					String domainName = context.getInitParameter("domainName");

					if(hostsMap.get(CommonLookup.DEV_EMAIL) == null){
						String[] to = {selectedProject.getOwner().getEmail()};
						emailUtil.setRecieverAddresses(to);
					}else{
						String[] to = {hostsMap.get(CommonLookup.DEV_EMAIL)};
						emailUtil.setRecieverAddresses(to);
					}
					
					String requestURL = "ac/project/approveinternationalprojectassignment.html";
					String privateLink = "http://" + hostsMap.get(CommonLookup.PRIVATEHOST) + "/" + domainName + "/" + requestURL+"?projectAssignmentId="+projectAssignment.getProjectAssignmentId();
					String publicLink = "http://" + hostsMap.get(CommonLookup.PUBLICHOST) + "/"	+ domainName + "/" + requestURL+"?projectAssignmentId="+projectAssignment.getProjectAssignmentId();
					String messageString = "Dear " + selectedProject.getOwner().getFirstName() + " " + selectedProject.getOwner().getLastName() + ",<br /><br />" + 
								"<a style='color:#FF9933;font-weight: bold;' href=\""+
								privateLink + "\">" + "Please click here to approve/reject international project assignment"+" "+projectAssignment.getProjectAssignmentCode() + "</a /><br /><br />"+
								"(Employees who are in Hyderabad office)"+"<br /><br />"+
								"<a style='color:#FF9933;font-weight: bold;' href=\""+
								publicLink + "\">" + "Please click here to approve/reject international project assignment"+" "+projectAssignment.getProjectAssignmentCode() + "</a /><br />"+
								"(Out side of Hyderabad office)"+"<br /><br />"+
				
							    "Thanks & Regards, <br />"
							    + CommonLookup.WAM_DEVTEAM_SIGNATURE;
					emailUtil.setMessage(messageString);
					emailUtil.setSenderEmail("podquick@erpanderp.com", "WAM - Dev Team");
					emailUtil.setSubject("International project assignment request-"+projectAssignment.getProjectAssignmentCode());
				
					SwingWorker worker = new SwingWorker<String, Object>() {
					@Override
					protected String doInBackground() throws Exception {
						EMAIL_MESSAGE = emailUtil.processAndSendEmail();
						return null;
					}
			
					@Override
					protected void done() {
							System.out.println("DONE " + EMAIL_MESSAGE);		
					}
					};
					worker.execute();
					System.out.println( "BEFORE RETURNING: " + EMAIL_MESSAGE);
					return EMAIL_MESSAGE;
				}
				
		//VALIDATION
		private void validateForm(){
			System.out.println("validateForm.....................");
			FORM_VALID = true;
			
			System.out.println("projectAssignment.getEmergencycontactNumber()....................."+projectAssignment.getEmergencycontactNumber());
			
			if(ValidationUtil.isEmpty(projectAssignment.getEmergencycontactNumber(), "Emergency Contact Number ", null, FacesContext.getCurrentInstance()) != null){
				FORM_VALID = false;
			}
			if(ValidationUtil.isEmpty(selectedProjectId.toString() , "Project", "", FacesContext.getCurrentInstance()) != null || ValidationUtil.isNonZero(selectedProjectId, "Project ", "", FacesContext.getCurrentInstance()) != null)
			{
				System.out.println("selectedProjectId.toString()...111111111........"+selectedProjectId.toString());
			FORM_VALID = false;
			}

			if(ValidationUtil.isEmpty(String.valueOf(visa.getVISANumber()), "Visa number ", null, FacesContext.getCurrentInstance()) != null){
				FORM_VALID = false;
			}
			if(ValidationUtil.isEmpty(visa.getValidUpto() != null ? visa.getValidUpto().toString() :null , "ValidUpto in visa details  ", null, FacesContext.getCurrentInstance()) != null){
				FORM_VALID = false;
			}
			if(ValidationUtil.isEmpty(String.valueOf(visa.getType()), "Visa type in visa details ", null, FacesContext.getCurrentInstance()) != null){
				FORM_VALID = false;
			}
			if(ValidationUtil.isEmpty(String.valueOf(visa.getCountry()), "Country in visa details ", null, FacesContext.getCurrentInstance()) != null){
				FORM_VALID = false;
			}
			if(ValidationUtil.isEmpty(String.valueOf(visa.getInsuranceProvider()), "Insurance provider in insurance details ", null, FacesContext.getCurrentInstance()) != null){
				FORM_VALID = false;
			}
			if(ValidationUtil.isEmpty(String.valueOf(visa.getInsurancePolicyNumber()), "Insurance policy number in insurance details  ", null, FacesContext.getCurrentInstance()) != null){
				FORM_VALID = false;
			}
			if(ValidationUtil.isEmpty(visa.getValidFrom() != null ? visa.getValidFrom().toString() :null , "Valid From in insurance details  ", null, FacesContext.getCurrentInstance()) != null){
				FORM_VALID = false;
			}
			if(ValidationUtil.isEmpty(visa.getValidTo() != null ? visa.getValidTo().toString() :null , "Valid To in insurance details  ", null, FacesContext.getCurrentInstance()) != null){
				FORM_VALID = false;
			}
			if(ValidationUtil.isEmpty(String.valueOf(visa.getWCCNumber()), "WCC number in project assignment allowance details  ", null, FacesContext.getCurrentInstance()) != null){
				FORM_VALID = false;
			}
			System.out.println("visa.getDailyAllowance()........."+visa.getDailyAllowance());
//			if(Long.valueOf(visa.getDailyAllowance()) = 0.0)
//			{
//				System.out.println("selectedProjectId.toString()...111111111........"+selectedProjectId.toString());
//			FORM_VALID = false;
//			}
			if(ValidationUtil.isEmpty(String.valueOf(visa.getPayCycle()), "Payment Cycle in project assignment allowance details  ", null, FacesContext.getCurrentInstance()) != null){
				FORM_VALID = false;
			}
			if(visa.getValidFrom() != null && visa.getValidTo() != null )
			{
			if(visa.getValidFrom().compareTo(visa.getValidTo())>0){
				
	    		System.out.println("FROMDATE is after TODATE");
	    		FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_WARN," Valid From should not be more than Valid To in insurance details", ""));
	    		FORM_VALID = false;
	    	}
			}
			System.out.println("Finally FORM_VALID is :::::"+FORM_VALID);
		}

		
		
		
		///INTERNATIONAL PROJECT ASSIGNMENT LIST
		public String viewProjectAssignmentInEditModeAction()
		{
			System.out.println("viewProjectAssignmentInEditMode");
			
			
			 System.out.println("===== viewProjectAssignmentInEditModeAction method=======");
	         try
	         {
	        	 
	          Map<String,String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
	          String projectAssignmentId = params.get("projectAssignmentId");
	          String employeeId = params.get("employeeId");
	          FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("projectAssignmentId", projectAssignmentId);
	          FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("employeeId", employeeId);
	          FacesContext.getCurrentInstance().getExternalContext().redirect("/wam/ac/project/editviewinternationalprojectassignment.html?projectAssignmentId="+projectAssignmentId+"&employeeId="+employeeId);
	          System.out.println("projectAssignmentId ==" + FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get("projectAssignmentId"));
	          System.out.println("employeeId ==" + FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get("employeeId"));
	         
	         }
	         catch (Exception e) 
	         {
	              System.out.println("INSIDE CATCH EXCPTION:::::::::"+e);
	              e.printStackTrace();
	         }
	         return "vieweditinternationalprojectassignment";
			}
		
		public void dialogClose(){	
			System.out.println("dialogClose .................");
			RequestContext.getCurrentInstance().execute("EditProjectAssignmentDialog.hide();");		
		}
		

		
	//GETTERS NAD SETTERS
	public String getSelectedButton() {
		return selectedButton;
	}
	public void setSelectedButton(String selectedButton) {
		this.selectedButton = selectedButton;
	}
	public boolean isCreateInternationalProjectAssignmentForm() {
		return createInternationalProjectAssignmentForm;
	}
	public void setCreateInternationalProjectAssignmentForm(
			boolean createInternationalProjectAssignmentForm) {
		this.createInternationalProjectAssignmentForm = createInternationalProjectAssignmentForm;
	}
	public boolean isInternationalProjectAssignmentsList() {
		return InternationalProjectAssignmentsList;
	}
	public void setInternationalProjectAssignmentsList(
			boolean internationalProjectAssignmentsList) {
		InternationalProjectAssignmentsList = internationalProjectAssignmentsList;
	}

	public HttpSession getSession() {
		return session;
	}

	public void setSession(HttpSession session) {
		this.session = session;
	}

	public HttpServletRequest getRequest() {
		return request;
	}

	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}

	public ServletContext getContext() {
		return context;
	}

	public void setContext(ServletContext context) {
		this.context = context;
	}

	public ProjectDAO getProjectDAO() {
		return projectDAO;
	}

	public void setProjectDAO(ProjectDAO projectDAO) {
		this.projectDAO = projectDAO;
	}

	public ProjectAssignmentDAO getProjectAssignmentDAO() {
		return projectAssignmentDAO;
	}

	public void setProjectAssignmentDAO(ProjectAssignmentDAO projectAssignmentDAO) {
		this.projectAssignmentDAO = projectAssignmentDAO;
	}

	public RRFDAO getRrfDAO() {
		return rrfDAO;
	}

	public void setRrfDAO(RRFDAO rrfDAO) {
		this.rrfDAO = rrfDAO;
	}

	public EmployeeAndReportingDAO getEmployeeAndReportingDAO() {
		return employeeAndReportingDAO;
	}

	public void setEmployeeAndReportingDAO(
			EmployeeAndReportingDAO employeeAndReportingDAO) {
		this.employeeAndReportingDAO = employeeAndReportingDAO;
	}

	public boolean isFORM_VALID() {
		return FORM_VALID;
	}

	public void setFORM_VALID(boolean fORM_VALID) {
		FORM_VALID = fORM_VALID;
	}

	public ProjectAssignment getProjectAssignment() {
		return projectAssignment;
	}

	public void setProjectAssignment(ProjectAssignment projectAssignment) {
		this.projectAssignment = projectAssignment;
	}

	public ProjectAssignmentDetail getProjectAssignmentDetail() {
		return projectAssignmentDetail;
	}

	public void setProjectAssignmentDetail(
			ProjectAssignmentDetail projectAssignmentDetail) {
		this.projectAssignmentDetail = projectAssignmentDetail;
	}

	public Journey getOnwardJourney() {
		return onwardJourney;
	}

	public void setOnwardJourney(Journey onwardJourney) {
		this.onwardJourney = onwardJourney;
	}

	public Journey getReturnJourney() {
		return returnJourney;
	}

	public void setReturnJourney(Journey returnJourney) {
		this.returnJourney = returnJourney;
	}

	public VISA getVisa() {
		return visa;
	}

	public void setVisa(VISA visa) {
		this.visa = visa;
	}

	public Employee getEmployee() {
		return employee;
	}

	public void setEmployee(Employee employee) {
		this.employee = employee;
	}

	public NewJoinee getNewJoinee() {
		return newJoinee;
	}

	public void setNewJoinee(NewJoinee newJoinee) {
		this.newJoinee = newJoinee;
	}

	public PassportAndPANDetails getPassportAndPANDetails() {
		return passportAndPANDetails;
	}

	public void setPassportAndPANDetails(PassportAndPANDetails passportAndPANDetails) {
		this.passportAndPANDetails = passportAndPANDetails;
	}

	public EmployeeAndReporting getEmployeeAndReporting() {
		return employeeAndReporting;
	}

	public void setEmployeeAndReporting(EmployeeAndReporting employeeAndReporting) {
		this.employeeAndReporting = employeeAndReporting;
	}

	public List<Project> getProjects() {
		return projects;
	}

	public void setProjects(List<Project> projects) {
		this.projects = projects;
	}

	public List<PassportAndPANDetails> getPassportAndPANDetailsList() {
		return passportAndPANDetailsList;
	}

	public void setPassportAndPANDetailsList(
			List<PassportAndPANDetails> passportAndPANDetailsList) {
		this.passportAndPANDetailsList = passportAndPANDetailsList;
	}

	public Map<String, Long> getProjectsMap() {
		return projectsMap;
	}

	public void setProjectsMap(Map<String, Long> projectsMap) {
		this.projectsMap = projectsMap;
	}

	public List<Journey> getOnwardJourneyDetails() {
		return onwardJourneyDetails;
	}

	public void setOnwardJourneyDetails(List<Journey> onwardJourneyDetails) {
		this.onwardJourneyDetails = onwardJourneyDetails;
	}

	public List<Journey> getReturnJourneyDetails() {
		return returnJourneyDetails;
	}

	public void setReturnJourneyDetails(List<Journey> returnJourneyDetails) {
		this.returnJourneyDetails = returnJourneyDetails;
	}

	public List<Journey> getOnwardJournies() {
		return onwardJournies;
	}

	public void setOnwardJournies(List<Journey> onwardJournies) {
		this.onwardJournies = onwardJournies;
	}

	public List<Journey> getReturnJournies() {
		return returnJournies;
	}

	public void setReturnJournies(List<Journey> returnJournies) {
		this.returnJournies = returnJournies;
	}

	public Long getSelectedProjectId() {
		return selectedProjectId;
	}

	public void setSelectedProjectId(Long selectedProjectId) {
		this.selectedProjectId = selectedProjectId;
	}

	public Project getSelectedProject() {
		return selectedProject;
	}

	public void setSelectedProject(Project selectedProject) {
		this.selectedProject = selectedProject;
	}

	public WAMUser getWamUser() {
		return wamUser;
	}

	public void setWamUser(WAMUser wamUser) {
		this.wamUser = wamUser;
	}

	public String getInternationalProjectAssignmentCode() {
		return InternationalProjectAssignmentCode;
	}

	public void setInternationalProjectAssignmentCode(
			String internationalProjectAssignmentCode) {
		InternationalProjectAssignmentCode = internationalProjectAssignmentCode;
	}

	public String getEmployeeId() {
		return employeeId;
	}

	public void setEmployeeId(String employeeId) {
		this.employeeId = employeeId;
	}

	public String getPassportNumber() {
		return passportNumber;
	}

	public void setPassportNumber(String passportNumber) {
		this.passportNumber = passportNumber;
	}

	public String getContactNumber() {
		return contactNumber;
	}

	public void setContactNumber(String contactNumber) {
		this.contactNumber = contactNumber;
	}

	public String getApprovedBy() {
		return approvedBy;
	}

	public void setApprovedBy(String approvedBy) {
		this.approvedBy = approvedBy;
	}

	public Float getAdvanceAmount() {
		return advanceAmount;
	}

	public void setAdvanceAmount(Float advanceAmount) {
		this.advanceAmount = advanceAmount;
	}

	public Float getRoomRentAdvance() {
		return roomRentAdvance;
	}

	public void setRoomRentAdvance(Float roomRentAdvance) {
		this.roomRentAdvance = roomRentAdvance;
	}

	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	public String getAdditionals() {
		return additionals;
	}

	public void setAdditionals(String additionals) {
		this.additionals = additionals;
	}

	public String getEMAIL_MESSAGE() {
		return EMAIL_MESSAGE;
	}

	public void setEMAIL_MESSAGE(String eMAIL_MESSAGE) {
		EMAIL_MESSAGE = eMAIL_MESSAGE;
	}

	public Employee getReportingManager() {
		return reportingManager;
	}

	public void setReportingManager(Employee reportingManager) {
		this.reportingManager = reportingManager;
	}

	public Long getReportingManagerId() {
		return reportingManagerId;
	}

	public void setReportingManagerId(Long reportingManagerId) {
		this.reportingManagerId = reportingManagerId;
	}

	public EmailUtil getEmailUtil() {
		return emailUtil;
	}

	public void setEmailUtil(EmailUtil emailUtil) {
		this.emailUtil = emailUtil;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	public ProjectAssignmentDetailDAO getProjectAssignmentDetailDAO() {
		return projectAssignmentDetailDAO;
	}


	public void setProjectAssignmentDetailDAO(
			ProjectAssignmentDetailDAO projectAssignmentDetailDAO) {
		this.projectAssignmentDetailDAO = projectAssignmentDetailDAO;
	}


	public boolean isSHOW_EDIT_DIALOG() {
		return SHOW_EDIT_DIALOG;
	}


	public void setSHOW_EDIT_DIALOG(boolean sHOW_EDIT_DIALOG) {
		SHOW_EDIT_DIALOG = sHOW_EDIT_DIALOG;
	}


	public boolean isRenderApproveReject() {
		return renderApproveReject;
	}


	public void setRenderApproveReject(boolean renderApproveReject) {
		this.renderApproveReject = renderApproveReject;
	}


	public boolean isRenderUpdate() {
		return renderUpdate;
	}


	public void setRenderUpdate(boolean renderUpdate) {
		this.renderUpdate = renderUpdate;
	}


	public boolean isRenderClose() {
		return renderClose;
	}


	public void setRenderClose(boolean renderClose) {
		this.renderClose = renderClose;
	}


	public boolean isRenderProjectsAssignmentsList() {
		return renderProjectsAssignmentsList;
	}


	public void setRenderProjectsAssignmentsList(
			boolean renderProjectsAssignmentsList) {
		this.renderProjectsAssignmentsList = renderProjectsAssignmentsList;
	}


	public boolean isRenderProjectsAssignments() {
		return renderProjectsAssignments;
	}


	public void setRenderProjectsAssignments(boolean renderProjectsAssignments) {
		this.renderProjectsAssignments = renderProjectsAssignments;
	}


	public List<ProjectAssignment> getProjectAssignmentsList() {
		return projectAssignmentsList;
	}


	public void setProjectAssignmentsList(
			List<ProjectAssignment> projectAssignmentsList) {
		this.projectAssignmentsList = projectAssignmentsList;
	}


	public List<ProjectAssignmentDetail> getProjectAssignmentDetailList() {
		return projectAssignmentDetailList;
	}


	public void setProjectAssignmentDetailList(
			List<ProjectAssignmentDetail> projectAssignmentDetailList) {
		this.projectAssignmentDetailList = projectAssignmentDetailList;
	}


	public Long getProjectAssignmentId() {
		return projectAssignmentId;
	}


	public void setProjectAssignmentId(Long projectAssignmentId) {
		this.projectAssignmentId = projectAssignmentId;
	}


	public String getProjectAssignmentCode() {
		return projectAssignmentCode;
	}


	public void setProjectAssignmentCode(String projectAssignmentCode) {
		this.projectAssignmentCode = projectAssignmentCode;
	}
	public JourneyDAO getOnwardJourneyDAO() {
		return onwardJourneyDAO;
	}






	public void setOnwardJourneyDAO(JourneyDAO onwardJourneyDAO) {
		this.onwardJourneyDAO = onwardJourneyDAO;
	}






	public JourneyDAO getReturnJourneyDAO() {
		return returnJourneyDAO;
	}






	public void setReturnJourneyDAO(JourneyDAO returnJourneyDAO) {
		this.returnJourneyDAO = returnJourneyDAO;
	}






	public TimeZone getDefaultTimeZone() {
		return defaultTimeZone;
	}






	public void setDefaultTimeZone(TimeZone defaultTimeZone) {
		this.defaultTimeZone = defaultTimeZone;
	}

	public EmployeeProject getEmployeeProject() {
		return employeeProject;
	}

	public void setEmployeeProject(EmployeeProject employeeProject) {
		this.employeeProject = employeeProject;
	}

	public EmployeeProjectDAO getEmployeeProjectDAO() {
		return employeeProjectDAO;
	}

	public void setEmployeeProjectDAO(EmployeeProjectDAO employeeProjectDAO) {
		this.employeeProjectDAO = employeeProjectDAO;
	}

	public List<EmployeeProject> getEmployeeProjects() {
		return employeeProjects;
	}

	public void setEmployeeProjects(List<EmployeeProject> employeeProjects) {
		this.employeeProjects = employeeProjects;
	}







}
